

;;; mp6-tests.scm
;;; Time-stamp: <2007-03-12 22:31:31 wand>

;;; this is copied from an old test harness.  Each test shows both a
;;; value and a type.  You will need to transform this to work with
;;; our new test harness, sorry. 

;;; Also, in the old version, false was represented by 0, so you'll
;;; have to change these to #f.  I've done the first couple.

;;; Also, in the old version, we used the syntax emptylist[Type]
;;; instead of emptylist_Type .  You'll have to change these and maybe
;;; other things.

(add-typed-test! 'mp6 'list-1 "list(11,22,33)"
  (11 22 33))

(add-typed-test! 'mp6 'list-of-lists-1
  "list(list(11,22),list(33))"
  ((11 22) (33)))

(add-typed-test! 'mp6 'list-broken-1
  "list(11,false)"
  'error '(11 #f))

(add-typed-test! 'mp6 'list-broken-2
  "list(list(11,22),list(false))"
  'error '((11 22) (#f)))

(add-typed-test! 'mp6 'type-of-cons-1
  "proc(x : int, y : listof int) cons(x,y)"
  '(int * (listof int) -> (listof int)) 'dontrun)

(add-typed-test! 'mp6 'list-ops-with-multiple-types-1
  "let f = proc(x : int, y : listof int) cons(x,y)
       g = proc(x : bool, y : listof bool) cons(x,y)
       true = zero?(0)
   in if car((g true emptylist[bool])) 
      then car(cdr(cons(2,(f 3 emptylist[int]))))
      else 4"
  'int 3)

(add-typed-test! 'mp6 'test-emptylist-1
  "emptylist[bool]"
  '(listof bool) '())

(add-typed-test! 'mp6 'test-emptylist-2
  "(proc(x : int) let y = emptylist[int] in cons(x,y) 
    33)"
'(listof int) '(33))

(add-typed-test! 'mp6 'test-car-1 "
(proc (x : listof int) car(x)
 list(11,22,33))"
'int 11)

(add-typed-test! 'mp6 'map-1 "
letrec
 listof bool map1 (f : (int -> bool), x : listof int) 
   = if null?(x) then emptylist[bool]
                 else cons( (f car(x)),
                            (map1 f cdr(x)) )
in (map1
     proc (x : int) zero?(x)
     list(22,0,33,44,0))"
'(listof bool) '(0 1 0 0 1))

(add-typed-test! 'mp6 'map-2 "
let map1 = proc (f : (int -> bool), x : listof int) 
            letrec 
             listof bool innerloop (x : listof int) 
              = if null?(x) 
                 then emptylist[bool]
                 else cons( (f car(x)),
                            (innerloop cdr(x)) )
             in (innerloop x)
in (map1
     proc (x : int) zero?(x)
     list(22,0,33,44,0))"
'(listof bool) '(0 1 0 0 1))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(add-typed-test!  "list(11,22,33)"
 (listof int) )

(add-typed-test! 
  "list(list(11,22),list(33))"
  (listof (listof int)))

(add-typed-test! 
  "list(11,false)"
  error )

(add-typed-test! 
  "list(list(11,22),list(false))"
  error )

(add-typed-test! 
  "proc(x : int, y : listof int) cons(x,y)"
  (int * (listof int) -> (listof int)) )

(add-typed-test! 
  "let f = proc(x : int, y : listof int) cons(x,y)
       g = proc(x : bool, y : listof bool) cons(x,y)
       true = zero?(0)
   in if car((g true emptylist[bool])) 
      then car(cdr(cons(2,(f 3 emptylist[int]))))
      else 4"
3)

(add-typed-test! 
  "emptylist[bool]"
  '(listof bool) )

(add-typed-test! 
  "(proc(x : int) let y = emptylist[int] in cons(x,y) 
    33)"
(listof int) )

(add-typed-test!  "
(proc (x : listof int) car(x)
 list(11,22,33))"
11)

(add-typed-test! "
letrec
 listof bool map1 (f : (int -> bool), x : listof int) 
   = if null?(x) then emptylist[bool]
                 else cons( (f car(x)),
                            (map1 f cdr(x)) )
in (map1
     proc (x : int) zero?(x)
     list(22,0,33,44,0))"
(listof bool) )

(add-typed-test!  "
let map1 = proc (f : (int -> bool), x : listof int) 
            letrec 
             listof bool innerloop (x : listof int) 
              = if null?(x) 
                 then emptylist[bool]
                 else cons( (f car(x)),
                            (innerloop cdr(x)) )
             in (innerloop x)
in (map1
     proc (x : int) zero?(x)
     list(22,0,33,44,0))"
(listof bool) )
